<template>
  <el-dialog :id="target" :close-on-click-modal="closeonclickmodal" width="50%" :title="getdialogTitle()"
             @open="listenopen()"
             @close="close" :visible="dialogshow">
    <el-form :model="dialoginfo" ref="dialoginfo" label-position="left">
      <el-row>
        <el-col :span="11">
          <el-form-item :rules="[{ required: true, message: '不能为空'}]"
                        prop="name" label="任务名" :label-width="formLabelWidth">
            <el-input type="text" v-model.trim="dialoginfo.name" auto-complete="off" clearable></el-input>
          </el-form-item>
          <el-form-item :rules="[{ required: true, message: '不能为空'}]"
                        prop="groupName" label="任务组" :label-width="formLabelWidth">
            <el-input type="text" v-model.trim="dialoginfo.groupName" auto-complete="off" clearable></el-input>
          </el-form-item>
          <el-form-item :rules="[{ required: true, message: '不能为空'}]"
                        prop="methodName" label="方法名" :label-width="formLabelWidth">
            <el-input type="text" v-model.trim="dialoginfo.methodName" auto-complete="off" clearable></el-input>
          </el-form-item>
          <el-form-item :rules="[{ required: true, message: '不能为空'}]"
                        prop="beanClass" label="映射类名" :label-width="formLabelWidth">
            <el-input type="text" v-model.trim="dialoginfo.beanClass" auto-complete="off" clearable></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="1">&nbsp;</el-col>
        <el-col :span="11">
          <el-form-item :rules="[{ required: true, message: '不能为空'}]"
                        prop="cron" label="执行周期" :label-width="formLabelWidth">
            <el-input type="text" v-model.trim="dialoginfo.cron" auto-complete="off" clearable></el-input>
          </el-form-item>
          <el-form-item :rules="[
                      { required: true, message: '必须选择一项'}
                    ]" prop="taskState" label="任务状态" :label-width="formLabelWidth">
            <el-select clearable v-model.trim="dialoginfo.taskState" placeholder="请选择">
              <el-option label="启用" :value="true"></el-option>
              <el-option label="禁用" :value="false"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item :rules="[{ required: true, message: '不能为空'}]"
                        prop="gameId" label="任务ID" :label-width="formLabelWidth">
            <el-input-number type="gameId" v-model.trim="dialoginfo.gameId" auto-complete="off" clearable></el-input-number>
          </el-form-item>
          <el-form-item :rules="[{ required: true, message: '不能为空'}]"
                        prop="descript" label="备注" :label-width="formLabelWidth">
            <el-input type="text" v-model.trim="dialoginfo.descript" auto-complete="off" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col>
          <el-form-item :rules="[{ required: true, message: '不能为空'}]"
                        prop="param" label="任务参数" :label-width="formLabelWidth">
            <el-input type="text" v-model.trim="dialoginfo.param" auto-complete="off" clearable></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-form-item style="text-align: right">
          <el-button size="mini" @click="dialogshow = false">取 消</el-button>
          <el-button size="mini" type="primary" @click="toAdd('dialoginfo')">保 存</el-button>
        </el-form-item>
      </el-row>
    </el-form>
  </el-dialog>
</template>
<script>
  export default {
    inject: ["reload"],
    data() {
      return {
        target: "dialogContainer",
        isajax: false,
        closeonclickmodal: true,
        formLabelWidth: '80px'
      }
    },
    props: ['dialogshow', 'dialoginfo', 'isadd','dialogurl'],
    methods: {
      getdialogTitle() {
        return this.isadd == true ? "新增定时任务" : "修改定时任务";
      },
      listenopen() {
        if (this.isadd && this.$refs['dialoginfo'] != null) {
          this.$refs['dialoginfo'].resetFields();
        }
        // console.log(this.isadd);
        // console.log(this.dialogshow);
      },
      close() {
        this.$emit('changedialogshow');
      },
      toAdd(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$store.commit("saveLoadingMap", {"target": this.dialogurl,id:this.target});
            this.proAPI.postJson(this.dialogurl, this.dialoginfo).then((res) => {
              this.$message.success({
                "message": res.message
              })
              this.reload();
            });
          } else {
            return false;
          }
        });
      }
    },
    updated() {
      // console.log(333);
    },
    mounted() {
      // console.log("开始创建！！！！！！！！！！！！！！！！！");
    }
  };
</script>
<style scoped>
  #userage >>> .el-input-number .el-input__inner {
    text-align: left;
  }
  #imageUpload >>> .el-upload--picture{
    background-color: #fbfdff;
    border: 1px dashed #c0ccda;
    border-radius: 6px;
    box-sizing: border-box;
    width: 64px;
    height: 64px;
    line-height: 64px;
    vertical-align: top;
  }

  #userBaseInfoEdit >>> .el-dialog__body {
    padding: 15px 20px;
    color: #606266;
    font-size: 14px;
  }
</style>
